﻿@using System.ComponentModel.DataAnnotations

<MForm Model="_model"
       OnValidSubmit="HandleOnValidSubmit"
       OnInvalidSubmit="HandleOnInvalidSubmit">
    <MTextField @bind-Value="_model.Name"
                Counter="10"
                Filled
                Label="Name">
    </MTextField>
    <MTextField @bind-Value="_model.Email"
                Filled
                Label="E-mail">
    </MTextField>
    <MSelect @bind-Value="_model.Item"
             Items="@_items"
             Filled
             Label="Item"
             ItemText="u => u"
             ItemValue="u => u">
    </MSelect>
    <MCheckbox @bind-Value="_model.Agree"
               Label="Do you agree?">
    </MCheckbox>
    <MButton Type="submit">Submit</MButton>
</MForm>

@code {

    class Model
    {
        [Required]
        [MaxLength(10, ErrorMessage = "Name must be less than 10 characters")]
        public string Name { get; set; }

        [Required] [EmailAddress] public string Email { get; set; }
        [Required] public string Item { get; set; }

        [RegularExpression("True", ErrorMessage = "You must agree to continue!")]
        public bool Agree { get; set; }
    }

    private bool _valid = true;
    private MForm _form;
    private Model _model = new();

    List<string> _items = new()
    {
        "Item 1",
        "Item 2",
        "Item 3",
        "Item 4"
    };

    private void HandleOnValidSubmit()
    {
        //valid
    }

    private void HandleOnInvalidSubmit()
    {
        //invalid
    }

}